package iset.coverageanalyzer;

import java.io.IOException;

import org.dom4j.DocumentException;

import iset.coverageanalyzer.config.ConfigInfo;
import iset.coverageanalyzer.config.ConfigTool;
import iset.coverageanalyzer.data.CoverageInfo;
import iset.coverageanalyzer.input.XMLAnalyzer;
import iset.coverageanalyzer.instrument.JavaInstrumentor;
import iset.coverageanalyzer.output.JPFGenerator;
import iset.coverageanalyzer.output.JPFInfo;

public class AnalyzerEntry {
	
	/**
	 * 
	 */
	public static void main(String[] args){
		
		// load basic config information
		ConfigInfo configInfo = ConfigTool.loadConfig("config.properties");
		
		// load input and analyze it
		XMLAnalyzer xmlAnalyzer = new XMLAnalyzer(configInfo);
		CoverageInfo coverageInfo = null;
		try {
			coverageInfo = xmlAnalyzer.analyzeXml();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// instrument code and output instrumented code
		JavaInstrumentor ji = new JavaInstrumentor(coverageInfo);
		try {
			ji.instrument();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// generate .jpf file
		JPFInfo jpfInfo = new JPFInfo();
		jpfInfo.standardInit();
		
		jpfInfo.addKeyValue("jpf.report.console.finished", coverageInfo.extractJPFTarget());
		jpfInfo.addKeyValue("target", coverageInfo.extractJPFTarget());
		jpfInfo.addKeyValue("symbolic.method", coverageInfo.extractJPFMethod());
		
		try {
			JPFGenerator.generate(configInfo.outputJPF, jpfInfo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
